package eu.ahsx.limboa.utils
{
	/**
	 * 	Utility class to retrieve a parameter contained in an objet.
	 * 	
	 * 	@author Masy Alexandre
	 * */
	public class Params
	{
		/**
		 * 	Retrieve a string contained in an object
		 * 	
		 * 	@param	name String	Name of the properties to look for
		 * 	@param	from Object	Object to look in
		 * 	@param	or String	Alternative value if not set
		 * 	@return String
		 * */
		public static function getStringOr(name:String, from:Object, or:String = ""):String
		{
			return getOr(name, from, or) as String;
		}
		
		/**
		 * 	Retrieve an int contained in an object
		 * 
		 * 	@param	name String	Name of the properties to look for
		 * 	@param	from Object	Object to look in
		 * 	@param	or int	Alternative value if not set
		 * 	@return int
		 * */
		public static function getInt(name:String, from:Object, or:int):int
		{
			return parseInt( getOr(name, from, or), 10 );
		}
		
		
		/**
		 * 	Retrieve an number contained in an object
		 * 
		 * 	@param	name String	Name of the properties to look for
		 * 	@param	from Object	Object to look in
		 * 	@param	or Number Alternative value if not set
		 * 	@return Number
		 * */
		public static function getNumber(name:String, from:Object, or:int):Number
		{
			return parseFloat( getOr(name, from, or) );
		}
		
		/**
		 * 	Retrieve an boolean contained in an object
		 * 
		 * 	@param	name String	Name of the properties to look for
		 * 	@param	from Object	Object to look in
		 * 	@param	or Boolean Alternative value if not set
		 * 	@return Boolean
		 * */
		public static function getBool(name:String, from:Object, or:Boolean):Boolean
		{
			return Boolean(getOr(name, from, or)); 
		}
		
		/**
		 * 	Retrieve a properties from an object
		 * 
		 * 	@param	name	String
		 * 	@param	from	Object
		 * 	@return *
		 * */
		public static function getOrNull(name:String, from:Object):*
		{
			return getOr(name, from, null);
		}
		
		/**
		 * 	Retrieve a properties from an object. If not set the alternative value is given
		 * 	
		 * 	@param	name String
		 * 	@param	from	Object
		 * 	@param	or	*
		 * 	@return *
		 * */
		public static function getOr(name:String, from:Object, or:*):*
		{
			var ret:* = or;
			
			if (from[name])
				ret = from[name];
			
			return ret;
		}
	}
}